// pages/activity_list/activity_list.js
import wxParse from "../../wxParse/wxParse.js"
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activity_list: [],
    selected: 0,
    titleArr: [],
    tabList: [],
    banners: []

  },
  isLogin(event) {
    console.log(555)
    wxParse.isLogin(event)
  },
  call(event) {
    wxParse.call(event)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    // wx.setStorageSync('turnType', options.turnType)
    this.setData({
      tel: wx.getStorageSync('phoneNumber')
    })

  },
  onShow: function() {
    var tabtype = wx.getStorageSync('turnType')
    if (!tabtype) {
      tabtype = 0
    }
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: "https://miniapp.odeman.com/summercamp/active_list.php?areaid=" + wx.getStorageSync('areaid'),
      header: {
        'Content-Type': 'application/json'
      },
      success: function(res) {
        wx.hideLoading()
        var titleArr = []
        var list = res.data.list
        for (var y in list) {
          titleArr.push({
            titleName: list[y].name
          })
        }
        that.setData({
          activity_list: list,
          titleArr: titleArr,
          banners: list[0].banners,
        })

        that.selected(null, tabtype)
      }

    })

  },
  onShareAppMessage: function (res) {
    console.log(wx.getStorageSync('areaid'))
    console.log(wx.getStorageSync('cityName'))
    return {
      title: this.data.title,
      desc: "这是描述",
      path: "/pages/activity_list/activity_list?areaid=" + wx.getStorageSync('areaid') +
        "&cityName=" + wx.getStorageSync('cityName')
    }
  },
  // onShareAppMessage: function () {
  //   return {
  //     title: '奥德曼夏令营',
  //   }
  // },
  //夏令营点击跳转
  navUrl: function(e) {
    var ids = e.currentTarget.dataset.id;
    wx.setStorageSync('ids', ids)
    wx.navigateTo({
      url: '../activity_detail/activity_detail'
    })
  },
  selected: function(e, tabtype) {
    var _this = this
    var type = -1
    if (e) {
      type = Number(e.currentTarget.dataset.type)
    } else {
      type = tabtype
    }
    wx.setStorageSync('turnType', type)
    this.setData({
      selected: type,
      tabList: _this.data.activity_list[type].lists,
      banners: _this.data.activity_list[type].banners
    })
  },

  footerNav: function(e) {
    var areaid = app.appData.userinfo.areaid;
    var userid = app.appData.userinfo.userid;
    var id = e.currentTarget.dataset.id;
    if (id == 1) {
      wx.navigateTo({
        url: '../index_index/index_index?areaid=' + areaid,
      })
    } else if (id == 2) {
      wx.navigateTo({
        url: '../activity_list/activity_list?areaid=' + areaid,
      })
    } else {
      wx.navigateTo({
        url: '../user/user?areaid=' + areaid + '&userid=' + userid,
      })
    }

  },

})